package com.sky.controller.admin;

import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.pojo.Employee;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.EmployeeService;
import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 员工管理
 *
 * @Author: Zhy
 * @Date: 2025-01-14 14:56
 * @Version: 1.0
 */
@RestController
@RequestMapping("/admin/employee")
@Slf4j
@Api(tags = "员工管理")
@RequiredArgsConstructor
public class EmployeeController {
	private final EmployeeService employeeService;

	/**
	 * 登录
	 *
	 * @return:
	 * @param: employeeLoginDTO
	 */
	@PostMapping("/login")
	@ApiOperation("员工登录")
	public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
		log.info("员工登录：{}", employeeLoginDTO);
		return employeeService.login(employeeLoginDTO);
	}

	/**
	 * 退出
	 *
	 * @return:
	 */
	@PostMapping("/logout")
	@ApiOperation("员工退出")
	public Result<String> logout() {
		return Result.success();
	}

	/**
	 * 新增员工
	 *
	 * @return:
	 * @param:
	 */
	@PostMapping
	@ApiOperation("新增员工")
	public Result<String> addEmployee(@RequestBody EmployeeDTO employeeDTO) {
		log.info("新增员工：{}", employeeDTO);

		return employeeService.addEmployee(employeeDTO);
	}

	/**
	 * 分页查询员工信息
	 *
	 * @return:
	 * @param: employeePageQueryDTO 分页查询参数
	 */
	@GetMapping("/page")
	@ApiOperation("分页查询员工信息")
	public Result<PageResult> selectPageQuery(EmployeePageQueryDTO employeePageQueryDTO){
		log.info("分页查询员工信息，employeePageQueryDTO:{}", employeePageQueryDTO);

		PageResult pageResult = employeeService.selectPageQuery(employeePageQueryDTO);
		return Result.success(pageResult);
	}

	/**
	 * 根据 id 查询员工信息
	 *
	 * @return:
	 * @param: id 用户id
	 */
	@GetMapping("/{id}")
	@ApiOperation("根据 id 查询员工信息")
	public Result<Employee> getEmployeeById(@PathVariable Long id) {
		log.info("根据 id 查询员工信息，id:{}", id);

		Employee employee = employeeService.getEmployeeById(id);
		return Result.success(employee);
	}

	/**
	 * 更新用户账户状态
	 *
	 * @return:
	 * @param: status 状态
	 * @param: id 用户id
	 */
	@PostMapping("/status/{status}")
	@ApiOperation("更新用户账户状态")
	public Result<String> startOrStop(@PathVariable Integer status, Long id) {
		log.info("更新用户账户状态，status:{}, id:{}", status, id);

		employeeService.startOrStop(status, id);
		return Result.success();
	}

	/**
	 * 更新用户信息
	 *
	 * @return:
	 * @param: employeeDTO 用户信息
	 */
	@PutMapping
	@ApiOperation("更新用户信息")
	public Result updateEmployee(@RequestBody EmployeeDTO employeeDTO) {
		log.info("更新用户信息，employeeDTO:{}", employeeDTO);

		employeeService.updateEmployee(employeeDTO);
		return Result.success();
	}

}
